import 'package:easy_video/internal/http_client.dart';
import 'package:dio/dio.dart';

class VideoApi {
  // 静态变量来保存唯一的实例
  static final VideoApi _instance = VideoApi._internal();

  // 私有构造函数
  VideoApi._internal();

  // 工厂构造函数
  factory VideoApi() {
    return _instance;
  }

  Future<Response> category() async {
    return HttpClient().get("/video_category/index");
  }

  Future<Response> index(
      {int? categoryId = null, String? title = null, int page = 0}) async {
    Map<String, dynamic> params = {
      "page": page,
    };
    if (categoryId != null) {
      params["category_id"] = categoryId;
    }
    if (title != null) {
      params["title"] = title;
    }
    return HttpClient().get("/video/index", queryParameters: params);
  }

  Future<Response> detail(int videoId) async {
    return HttpClient().get("/video/detail/${videoId}");
  }

  Future<Response> videoChannel(int videoId) async {
    return HttpClient().get("/video/channel/${videoId}");
  }

  Future<Response> videoChapter(int videoId, int channelId) async {
    return HttpClient().get("/video/chapter/${videoId}/${channelId}");
  }

  Future<Response> videoPlayUrl(int chapterId) async {
    return HttpClient().get("/video/m3u8/${chapterId}");
  }

  Future<Response> record(int chapterId, int second) async {
    return HttpClient().post("/video/record/${chapterId}", data: {
      "second": second,
    });
  }

  Future<Response> getRecord(int chapterId) async {
    return HttpClient().get("/video/record/${chapterId}");
  }
}
